home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / setjmp.cpp < prev    next >
C/C++ Source or Header  |  1993-09-15  |  2KB  |  94 lines

  1. |
  2. | setjmp.cpp 
  3. |
  4.  
  5.     .globl ___mint
  6.  
  7. #ifdef __MBASE__
  8. #define Mint    __MBASE__@(___mint)
  9. #define Sigmask    __MBASE__@(__sigmask)
  10. #else
  11. #define Mint    ___mint
  12. #define Sigmask __sigmask
  13. #endif
  14.  
  15.     .text
  16.     .even
  17.     .globl _sigsetjmp
  18. _sigsetjmp:
  19.     movel    sp@(4), a0        | address of sigjmp_buf[]
  20. #ifdef __MSHORT__
  21.     movew    sp@(8), a1
  22. #else
  23.     movel    sp@(8), a1
  24. #endif
  25.     movel    a1, a0@(52)        | save sigmask for siglongjmp?
  26.     beq    SETJMP            | no -- call common code
  27.     movel    Sigmask, d0        | save tos emulation signal mask
  28. #ifdef __MSHORT__
  29.     tstw    Mint            | see if MiNT is active
  30. #else
  31.     tstl    Mint
  32. #endif
  33.     beq    nomint            | no -- call common code
  34.     clrl    sp@-            | add no signals to sigmask
  35.     movew    #0x116, sp@-        | Psigblock() system call
  36.     trap    #1            |
  37.     addqw    #6, sp
  38. nomint:
  39.     orw    #1,d0            | make it != 0 (SIGNULL is unmaskable)
  40.     movel    d0, a0@(52)        | save signal mask
  41.     bra    SETJMP            | call common code
  42.  
  43.     .globl _setjmp
  44. _setjmp:
  45.     movel    sp@(4),a0        | address of jmp_buf[]
  46.     clrl    a0@(52)            | do not restore sigmask on longjmp
  47. SETJMP:
  48.     movel    sp@,a0@            | save return address
  49.     moveml    d2-d7/a2-a7,a0@(4)    | save registers d2-d7/a2-a7
  50.     clrl    d0            | return value is 0
  51.     rts
  52.  
  53.     .globl _siglongjmp
  54. _siglongjmp:
  55.     .globl _longjmp
  56. _longjmp:
  57. #ifdef __MSHORT__
  58.     tstw    Mint            | see if MiNT is active
  59. #else
  60.     tstl    Mint
  61. #endif
  62.     beq    NOMINT            | no -- do not call sigreturn
  63.     movew    #0x11a, sp@-        | Psigreturn() system call
  64.     trap    #1            | (ignored if not in a sig handler)
  65.     addqw    #2, sp
  66. NOMINT:
  67.     movel    sp@(4),a0        | address of jmp_buf[]
  68.     movel    a0@(52),d0        | want to restore sigmask?
  69.     beq    NORESTORE        | no -- skip restore code
  70.     andw    #-2,d0
  71.     movel    d0, Sigmask        | restore tos emulation signal mask
  72. #ifdef __MSHORT__
  73.     tstw    Mint            | see if MiNT is active
  74. #else
  75.     tstl    Mint
  76. #endif
  77.     beq    NORESTORE        | no -- do not call sigsetmask
  78.     movel    d0, sp@-        | restore signal mask
  79.     movew    #0x117, sp@-        | Psigsetmask() system call
  80.     trap    #1            |
  81.     addqw    #6, sp
  82. NORESTORE:
  83. #ifdef __MSHORT__
  84.     movew    sp@(8),d0        | value to return
  85. #else
  86.     movel    sp@(8),d0        | value to return
  87. #endif
  88.     bne    L1            | may not be 0
  89.     movql    #1, d0
  90. L1:
  91.     moveml    a0@(4),d2-d7/a2-a7    | restore saved reggies
  92.     movl    a0@,sp@            | and the saved return address
  93.     rts
  94.